package com.lj.back.manage.scaffold.config;

import com.lj.back.manage.scaffold.common.constant.RedisConstant;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.nio.charset.StandardCharsets;

/**
 * 自定义redis key 序列化类
 * @author lv
 * @version 1.0.0
 */
public class MyRedisKeySerializer extends StringRedisSerializer {

    @Override
    public String deserialize(byte[] bytes) {
        return bytes == null ? null : RedisConstant.KEY_PREFIX +(new String(bytes, StandardCharsets.UTF_8));
    }

    @Override
    public byte[] serialize(String string) {
        return super.serialize(string == null? null : RedisConstant.KEY_PREFIX + string);
    }
}
